//
//  Corp.swift
//  GroupPattern
//
//  Created by mac on 2017/11/16.
//  Copyright © 2017年 RRC. All rights reserved.
//

import Foundation

//抽象公司职员类：将Branch和Leaf类的职员信息抽象出来
public class Crop{
    ///名称
    var name = ""
    ///职位
    var position = ""
    ///薪水
    var salary = 0
    
    init(name:String, position:String, salary:Int) {
        self.name = name
        self.position = position
        self.salary = salary
    }
    
    ///获取信息
    func getInfo() -> String{
        var info = ""
        info = "姓名：" + self.name
        info = info + "\t职位：" + self.position
        info = info + "\t薪水：\(self.salary)"
        return info
    }
    
    //实现从下往上遍历
    ///父节点是谁
    private var parent:Crop?
    
    //设置父节点
    func setParent(parent:Crop){
        self.parent = parent
    }
    
    //得到父节点
    func getParent() -> Crop{
        return self.parent!
    }
    
    func find(){
        var parentStr = ""
        parentStr = (self.parent?.name)! + (self.parent?.position)! + "\((self.parent?.salary)!)"
        print(parentStr)
    }
}
